package com.hg.hggood.controller;

import com.hg.hggood.entity.Product;
import com.hg.hggood.service.IProductService;
import com.hg.hggood.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.Serializable;
import java.util.List;

@CrossOrigin(value = "http://localhost:8081")
@RequestMapping("products")
@RestController
public class ProductController extends BaseController{
    @Autowired
    private IProductService productService;

    @RequestMapping("hot_list")
    public JsonResult<List<Product>>getHotList(){
        List<Product> data = productService.findHotList();
        return new JsonResult<List<Product>>(OK,data);
    }

    @GetMapping("{id}/details")
    public JsonResult<Product> getById(@PathVariable("id") Integer id){
        //调用业务对象执行获取数据
        Product data = productService.findById(id);
        //返回成功和数据
        return new JsonResult<Product>(OK,data);
    }
}
